//
//  LXNavBarView.m
//  cat
//
//  Created by imera on 16/1/18.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXMainNavBarView.h"

#define LXNavBarViewMargin 10

@implementation LXMainNavBarView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        [self initSubViews];
    }
    return self;
}


- (void)initSubViews
{
    UIImageView *logoImageView = [[UIImageView alloc]init];
    logoImageView.image = [UIImage imageNamed:@"logo"];
    CGFloat logoImageViewX = LXNavBarViewMargin;
    CGFloat logoImageViewY = 0;
    CGFloat logoImageViewH = self.frame.size.height;
    CGFloat logoImageViewW = logoImageViewH;
    logoImageView.frame = CGRectMake(logoImageViewX, logoImageViewY, logoImageViewW, logoImageViewH);
    [self addSubview:logoImageView];
    
    UIImageView *logoImageView1 = [[UIImageView alloc]init];
    logoImageView1.contentMode = UIViewContentModeScaleAspectFit;
    logoImageView1.image = [UIImage imageNamed:@"logo-font"];
    CGFloat logoImageView1Y = 0;
    CGFloat logoImageView1W = 200;
    CGFloat logoImageView1X = (self.frame.size.width - logoImageView1W) * 0.5;
    CGFloat logoImageView1H = self.frame.size.height;
    logoImageView1.frame = CGRectMake(logoImageView1X, logoImageView1Y, logoImageView1W, logoImageView1H);
    [self addSubview:logoImageView1];
    
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [searchBtn setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
    CGFloat searchBtnY = 0;
    CGFloat searchBtnW = 25;
    CGFloat searchBtnH = self.frame.size.height;
    CGFloat searchBtnX = self.frame.size.width - searchBtnW - LXNavBarViewMargin;
    searchBtn.frame = CGRectMake(searchBtnX, searchBtnY, searchBtnW, searchBtnH);
    [self addSubview:searchBtn];
}

- (void)search
{
    if ([self.MyDelagate respondsToSelector:@selector(mainNavBarView:)]) {
        [self.MyDelagate mainNavBarView:self];
    }
}

@end
